/**
 * Assignment 1.  Write a series of junit tests in a separate test file named TaxTests.java.
 * These tests should adequately test the following code.
 * Submit these tests, plus some documentation of your results via moodle.  The documentation
 * may be submitted separately via hard copy if desired.
 *
 * The documentation of the results doesn't need to be fancy -- just a short indication
 * of which tests passed and which failed, plus any behavior where the specification is
 * unclear, or where you feel that the behavior is not desirable from a user perspective.
 * In those cases where the specification is unclear or the behavior is undesirable, be sure
 * to explain why you feel this, and make a recommendation for what you think the behavior should
 * be.  Your tests should reflect these recommendations.
 *
 * To recap, you will submit:
 * TaxTests.java:  your junit tests via moodle.
 * Documentation of your results, either via moodle or hardcopy
 *
 * Due:  Friday, Sept 23, by midnight.
 */
package cs2320;


/**
 * A static class with a series of methods for calculating the pay and taxes for an individual over
 * a single week.
 *
 * @author ldamon
 *
 */
public class TaxCalculator {

    /**
     * Calculates the tax for a given gross pay.  This method incorporates the
     * current marginal tax tables, and the threshold levels at which the differing
     * levels of tax apply.
     *
     * <ul>
     * <li>rate1:  tax rate for the first rate1Threshold earnings
     * <li>rate2:  tax rate for earnings above rate1Threshold, but less than rate2Threshold
     * <li>rate3:  tax rate for earnings above rate2Threshold
     * </ul>
     * @param hours the hours worked by the individual
     * @return the tax due from the individual, given the number of hours
     */
    public static double calculateTax(double hours)
    {
        final double rate1 = .15;
        final double rate1Threshold = 337.50;
        final double rate2 = .20;
        final double rate2Threshold = 487.50;
        final double rate3 = .25;

        double tax = 0;
        double gross = TaxCalculator.calculateGross(hours);

        if (gross <= rate1Threshold)
            tax = gross * rate1;
        else
            tax = rate1Threshold * rate1;
        if (gross > rate1Threshold && gross <= rate2Threshold)
            tax = tax + (gross - rate1Threshold) * rate2;
        else if (gross > rate2Threshold)
            tax = tax + (rate2Threshold - rate1Threshold) * rate2 +
            (gross - rate2Threshold) * rate3;

        return tax;
    }



    /**
     * Calculate the gross pay for the given hours.  A normal work week is
     * 40 hours, with time and half being paid for any time over those 40 hours
     * @param hours number of hours worked in the week
     * @return the gross pay, given a pay rate of 12.50 per hour
     */
    public static double calculateGross(double hours)
    {
        final int regHours = 40;
        final double payRate = 12.50;

        if (hours < regHours)
            return hours * payRate;
        else
            return regHours * payRate + (hours - regHours) * payRate * 1.5;   
    }
   
   
    /**
     * Calculate the net pay for the given hours.
     */
    public static double calculateNet(double hours)
    {
        double gross = calculateGross(hours);
        double tax = calculateTax(hours);
        return gross - tax;
    }

}